#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>
#include<sys/stat.h>

int main()
{
  umask(0);
  int fd = open("temp.txt",O_RDWR|O_CREAT|O_TRUNC,0664);
  if(fd<0)
  {
    perror("open error");
    return -1;
  }

  char *data = "今天过年咯，看春晚\n";
  ssize_t ret =  write(fd,data,strlen(data));
  if(ret<0)
  {
    perror("ret error");
    close(fd);
    return -1;
  }

  lseek(fd,0,SEEK_SET);
  char buf[1024]={0};
  ret = read(fd,buf,1023);
  if(ret<0)
  {
    perror("read error");
    close(fd);
    return -1;
  }

  printf("%s\n",buf);
  close(fd);
  return 0;
}
